package com.viewplug.listView;


import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.viewplug.R;

/**
 * Created by mac_wk on 14-10-27.
 */
public class ListViewFooter extends LinearLayout {

    public final static int STATE_NORMAL=0;
    public final static int STATE_READY=1;
    public final static int STATE_LOADING=2;
    private Context context;
    private View mContentView;
    private View mProgressBar;
    private TextView mHintView;
    private Context mContext;

    public ListViewFooter(Context context) {
        super(context);
        initView(context);
    }
    public void setState(int state)
    {
        mHintView.setVisibility(View.INVISIBLE);
        mProgressBar.setVisibility(View.INVISIBLE);
        mHintView.setVisibility(View.INVISIBLE);
        if (state==STATE_READY){
            mHintView.setVisibility(View.VISIBLE);
            mHintView.setText(R.string.view_plug_footer_hint_ready);

        }else if (state==STATE_LOADING)
        {
            mProgressBar.setVisibility(View.VISIBLE);

        }else
        {
            mHintView.setVisibility(View.VISIBLE);
            mHintView.setText(R.string.view_plug_footer_hint_normal);
        }
    }
    public void setBottomMargin(int height)
    {
        if (height < 0)
            return;
        LayoutParams lp = (LayoutParams) mContentView.getLayoutParams();
        lp.bottomMargin = height;
        mContentView.setLayoutParams(lp);
    }
    public int getBottomMargin()
    {
        LayoutParams lp = (LayoutParams) mContentView.getLayoutParams();
        return lp.bottomMargin;
    }
    /**
     * normal status
     */
    public void normal() {
        mHintView.setVisibility(View.VISIBLE);
        mProgressBar.setVisibility(View.GONE);
    }


    /**
     * loading status
     */
    public void loading() {
        mHintView.setVisibility(View.GONE);
        mProgressBar.setVisibility(View.VISIBLE);
    }

    /**
     * hide footer when disable pull load more
     */
    public void hide() {
        LayoutParams lp = (LayoutParams)mContentView.getLayoutParams();
        lp.height = 0;
        mContentView.setLayoutParams(lp);
    }
    /**
     * show footer
     */
    public void show() {
        LayoutParams lp = (LayoutParams)mContentView.getLayoutParams();
        lp.height = LayoutParams.WRAP_CONTENT;
        mContentView.setLayoutParams(lp);
    }
    private void initView(Context context) {
        mContext = context;
        LinearLayout moreView = (LinearLayout)LayoutInflater.from(mContext).inflate(R.layout.view_plug_listview_footer, null);
        addView(moreView);
        moreView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

        mContentView = moreView.findViewById(R.id.viewplug_listview_footer_content);
        mProgressBar = moreView.findViewById(R.id.viewplug_listview_footer_progressbar);
        mHintView = (TextView)moreView.findViewById(R.id.viewplug_listview_footer_hint_textview);
    }

    public ListViewFooter(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public ListViewFooter(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    @TargetApi(Build.VERSION_CODES.L)
    public ListViewFooter(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        initView(context);
    }




}
